
var userList = [];

/*获取用户列表*/
$("#getUserList").click(function () {
    // switchDiv('userUl');
    userGetList();
});
console.timeEnd

function userGetList() {
    console.log(localStorage["token"])
    $.ajax({
        type: "get",
        url: url + "/user/userall.php",
        data: "",
        dataType: "json",
        success: function (data) {
            console.log(data);
            $("#userUl").empty();
            $("#userUl").append(
                "<li><span>用户名</span><span>最近登录时间</span><span>操作</span></li>")
            userList = [];
            userList = data.content;
            for (var i = 0 in userList) {
                $("#userUl  li:first").after("<li><span>" + userList[i].username + "</span><span>" +
                    userList[i].time + "</span><a href='#'><span data-id=" + userList[i].id +
                    " data-name=" + userList[i].username + ">删除</span></a></li>");
            }
            $("#userUl  li:even").css("background-color", "#fff");
            $("#userUl  li:odd").css("background-color", "#f5f5f5");
        }
    });
}
userGetList()
/*删除用户*/
$("#userUl").click(function (even) {
    // console.log(even);     
    console.log(even.target.outerText);
    if (even.target.outerText == "删除") {
        console.log(even.target.dataset.id);
        $.ajax({
            type: "post",
            url: url + "/user/del.php",
            data: {
                username: even.target.dataset.name,
                id: even.target.dataset.id,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
                hint(data.msg);
                userGetList();
            }
        });
    }
});